/*
 * @FileName: easy_filter.h
 * @Author: GreyQiu qiushaogui@aikosolar.com
 * @Date: 2023-07-18 11:31:00
 * @LastEditors: GreyQiu qiushaogui@aikosolar.com
 * @LastEditTime: 2023-08-09 14:15:09
 * @Description: 
 * 
 * Copyright (c) 2023, All Rights Reserved. 
 */
#ifndef __FILTER_H__
#define __FILTER_H__

/**
 * @description: 一阶低通滤波器
 */
typedef struct {
    float A;  // 离散滤波器系数 A = Wc*Ts/(1+Wc*Ts)
    float B;  // 离散滤波器系数 B = 1 - A
    float Yn_1;
} easy_lpf_f32_t;

/**
 * @description: Process function for the LPF
 * @return 滤波后的结果
 */
static inline float easy_lpf_f32(easy_lpf_f32_t * S, float in) {
    /* u[k] = B * u[k - 1] + A * e[k]  */
    float out = S->B * S->Yn_1 + S->A * in;
    S->Yn_1 = out;
    return (out);
}

void easy_lpf_config_f32(easy_lpf_f32_t * S, float Fc, float Ts);

#endif // __FILTER_H__
